package com.wodsy.phoenix.dataobject.base;

import java.util.Collection;

/**
 * 名称：com.wodsy.phoenix.dataobject.base
 * 描述：<br>用于包装返回的对象
 *  返回code，参考{@link com.wodsy.phoenix.dataobject.base.ResponseCodeConstants}
 * 类型：JAVA<br>
 * 最近修改时间：11/03/2015 10:20<br>
 *
 * @author Jack Chan
 * @since 11/03/2015
 */
public class PhoenixResponseWrapper<T extends PhoenixResponse> implements java.io.Serializable {
    private static final long serialVersionUID = 1L;

    /**
     *  返回code，参考{@link com.wodsy.phoenix.dataobject.base.ResponseCodeConstants}
     */
    private Integer code = ResponseCodeConstants.SUCCESS;
    /**
     * 错误消息
     */
    private String msg = "success";
    /**
     * 如果是分页对象，则放入pager中
     */
    private Pager<T> pager;
    /**
     * 如果是单一对象，则放入obj中
     */
    private T obj;

    private Collection<T> items;

    public PhoenixResponseWrapper() {
    }

    public PhoenixResponseWrapper(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public PhoenixResponseWrapper(Pager<T> pager) {
        this.pager = pager;
    }

    public PhoenixResponseWrapper(T obj) {
        this.obj = obj;
    }

    public PhoenixResponseWrapper(Pager<T> pager, T obj) {
        this.pager = pager;
        this.obj = obj;
    }

    public PhoenixResponseWrapper(Integer code, String msg, Pager<T> pager, T obj) {
        this.code = code;
        this.msg = msg;
        this.pager = pager;
        this.obj = obj;
    }

    public PhoenixResponseWrapper(Integer code, String msg, Collection<T> items) {
        this.code = code;
        this.msg = msg;
        this.items = items;
    }

    public PhoenixResponseWrapper(Collection<T> items) {
        this.items = items;
    }

    public boolean isOK(){
        return this.code == ResponseCodeConstants.SUCCESS;
    }

    public Integer getCode() {
        return code;
    }

    public String getMsg() {
        return msg;
    }

    public Pager<T> getPager() {
        return pager;
    }

    public T getObj() {
        return obj;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public void setPager(Pager<T> pager) {
        this.pager = pager;
    }

    public void setObj(T obj) {
        this.obj = obj;
    }

    public Collection<T> getItems() {
        return items;
    }

    public void setItems(Collection<T> items) {
        this.items = items;
    }
}
